package com.dq.config;

import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: feihu.wang
 * @create: 2023-09-05 14:04
 * 设计http请求头大小header 大小
 **/
@Configuration
public class TomcatHeaderConfig {

    @Bean
    public WebServerFactoryCustomizer<TomcatServletWebServerFactory> customizeTomcat() {
        return factory -> {
            // 配置最大 HTTP 头部大小为 10MB (10 * 1024 * 1024 字节)
            factory.addConnectorCustomizers(connector -> {
                // 获取协议处理器并设置最大头部大小
                org.apache.coyote.http11.Http11NioProtocol protocol =
                        (org.apache.coyote.http11.Http11NioProtocol) connector.getProtocolHandler();
                protocol.setMaxHttpHeaderSize(10 * 1024 * 1024);
            });
        };
    }
}

